package com.cheng.example.book.advise151.chap1;

import java.text.NumberFormat;

public class Client04 {
    public static void main(String[] args) {
        Client04 client = new Client04();
        // 499元的货物 打75折
        client.calPrice(499, 75);
    }
    // 简单折扣计算
    public void calPrice(int price, int discount) {
        float knockdownPrice = price * discount / 100.0F;
        System.out.println("简单折扣后的价格是：" + formatCurrency(knockdownPrice));
    }
    // 复杂多折扣计算
    public void calPrice(int price, int... discounts) {
        float knockdownPrice = price;
        for (int discount : discounts) {
            knockdownPrice = knockdownPrice * discount / 100;
        }
        System.out.println("复杂折扣后的价格是：" + formatCurrency(knockdownPrice));
    }
    public String formatCurrency(float price) {
        return NumberFormat.getCurrencyInstance().format(price);
    }
}
